<template>
  <div>
    <!-- 头部 -->
    <!-- <headers class="head"></headers> -->
    <!-- hahahahaha -->

    <!-- 分类 -->
    <div class="navigation contents">
      <img src="../assets/home/logo2.png" />
      <el-menu
        class="el-menu-demo"
        mode="horizontal"
        @select="handleSelect"
        background-color="#515a6e"
        text-color="#fff"
        active-text-color="#cbced4"
        default-active="/"
      >
        <el-menu-item index="/" @click="shouye_01()">首页</el-menu-item>
        <el-submenu index="2">
          <template slot="title">论文分类</template>
          <el-menu-item
            v-for="(item, index) in fl"
            :key="index"
            @click="ceshi(item.name)"
            >{{ item.name }}</el-menu-item
          >
        </el-submenu>
        <el-menu-item index="3" :style="active" @click="userDisplays"
          ><div
            class="denglu"
            @mouseenter="enterFun()"
            @mouseleave="leaveFun()"
          >
            {{ login }}
          </div></el-menu-item
        >
        <el-menu-item @click="publish_02()" index="4">{{
          publish
        }}</el-menu-item>
      </el-menu>
    </div>
    <!-- 用户详情 -->
    <div
      class="users"
      v-show="userDisplay"
      @mouseenter="enterFun()"
      @mouseleave="leaveFun()"
    >
      <div class="usersz">
        <el-avatar icon="el-icon-user-solid" class="icon"></el-avatar>
        <p @click="myPaper"><i class="el-icon-document"></i>我的论文</p>
        <p @click="downLogin" style="margin-top: 5px">
          <i class="el-icon-key"></i>退出登录
        </p>
      </div>
    </div>
    <div v-if="shouye">
      <!-- 跑马灯 -->
      <div class="block">
        <Carousel autoplay v-model="value2" loop>
          <CarouselItem>
            <div class="demo-carousel1"></div>
          </CarouselItem>
          <CarouselItem>
            <div class="demo-carousel2"></div>
          </CarouselItem>
          <CarouselItem>
            <div class="demo-carousel3"></div>
          </CarouselItem>
          <CarouselItem>
            <div class="demo-carousel4"></div>
          </CarouselItem>
        </Carousel>
      </div>
      <!-- 公告 -->
      <div class="gonggao">
        <ac ref="ac_01"></ac>
        <ac_02 class="ac_02"></ac_02>
      </div>
    </div>
    <!-- 发表论文 -->
    <newpaper v-if="fabiao"></newpaper>
    <!-- 底部 -->
    <footers></footers>
  </div>
</template>

<script>
// 组件的引用
import headers from "../components/Header.vue";
import footers from "../components/Footer.vue";
import ac from "../components/Ac.vue";
import ac_02 from "../components/Ac_02.vue";
import newpaper from "./newpaper.vue";
export default {
  components: { ac, headers, footers, ac_02, newpaper },
  data() {
    return {
      activeIndex: "1",
      activeIndex2: "1",
      fl: "",
      theme1: "dark",
      value2: 0,

      login: "登录",
      publish: "发表论文",
      userDisplay: false,
      active: "",
      fabiao: false,
      shouye: true,
    };
  },

  methods: {
    ceshi(names) {
      localStorage.setItem("fenlei", names);
      this.$refs.ac_01.ceshi();
    },
    //查询分类
    category() {
      this.$http.get("/category/").then((res) => {
        // console.log(res);
        this.fl = res.data;
        // console.log(this.fl);
      });
    },
    Jump(f) {
      console.log(111);
      this.$router.push({
        name: f,
        params: { title: "传输数据" },
      });
    },
    // 首页
    shouye_01() {
      this.fabiao = false;
      this.shouye = true;
    },
    // 发表论文
    publish_01() {
      if (localStorage.getItem("token_z")) {
        this.$notify({
          duration: 1500,
          title: "成功",
          message: "跳转成功，祝您编写愉快！",
          type: "success",
        });
        this.$router.push({ path: "/newpaper" });
      } else {
        this.$notify.error({
          duration: 1500,
          title: "错误",
          message: "您还未登录账号，请登录后发表论文！",
        });
        this.$router.push({ path: "/login" });
      }
      // console.log("aa");
    },
    publish_02() {
      if (localStorage.getItem("token_z")) {
        this.$notify({
          duration: 1500,
          title: "成功",
          message: "跳转成功，祝您编写愉快！",
          type: "success",
        });
        this.fabiao = true;
        this.shouye = false;
      } else {
        this.$notify.error({
          duration: 1500,
          title: "错误",
          message: "您还未登录账号，请登录后发表论文！",
        });
        this.$router.push({ path: "/login" });
      }
    },
    // 判断是登录还是用户
    mounted() {
      const z = localStorage.getItem("token_z");
      if (z) {
        this.login = "用户";
        // this.userDisp = true;
      } else {
        this.login = "登录";
        // this.userDisp = false;
      }
    },
    // 移入移出
    enterFun() {
      if (this.login == "用户") {
        // console.log("移入");
        this.userDisplay = true;
      }
    },
    leaveFun() {
      // console.log("移出");
      this.userDisplay = false;
    },
    // 登录
    userDisplays() {
      if (this.login == "登录") {
        this.$router.push({
          path: "/login",
        });
      }
    },
    // 我的论文
    myPaper() {
      this.$router.push({
        name: "tables",
      });
    },
    // 退出登录
    downLogin() {
      if (this.userDisplay == true) {
        this.userDisplay = false;
      }
      this.$notify({
        duration: 1500,
        title: "成功",
        message: "账号退出成功！",
        type: "success",
      });
      localStorage.removeItem("token_z");
      this.login = "登录";
    },
  },
  mounted() {
    this.category();
    this.mounted();
  },
};
</script>

<style scoped  lang="less">
.conTent {
  position: relative;
}
// 头部
.head {
  position: fixed;
  top: 0px;
  z-index: 999;
}
* {
  margin: 0;
  padding: 0;
}
/* 导航 */
.navigation {
  width: 100%;
  overflow: hidden;
  z-index: 999;
  // border: 1px solid #ff0000;
  background: #515a6e;
  display: flex;
  justify-content: flex-end;
}
.el-menu-demo {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  // border: 1px solid #ff0000;
  padding-right: 150px;
}
.navigation img {
  width: 150px;
  height: 50px;
  margin-top: 10px;
  margin-left: 150px;
  // border: 1px solid #ff0000;
}
/* logo */
// .logo {
//   float: left;
//   margin: 0;
//   padding: 0;
// padding-right: 40px;
// }
// .logo img {
//   width: 120px;
//   height: 35px;
//   padding-top: 15px;
//   display: block;
// }
.block {
  width: 100%;
  margin-top: -1px;
}
// .el-menu-item {
// font-family: "Courier New", Courier, monospace;
// font-size: 15px;
// }

.el-menu-item-right {
  margin-left: 930px;
}
.gonggao {
  // border: 1px solid #ff0000;
  width: 1200px;
  margin: 20px auto;
  // display: flex;
  // justify-content: left;
}
.demo-carousel1 {
  background: url(../assets/home/2.jpg);
  background-size: 100% 500px;
  height: 450px;
}
.demo-carousel2 {
  background: url(../assets/home/3.jpg);
  background-size: 100% 500px;
  height: 450px;
}
.demo-carousel3 {
  background: url(../assets/home/13.jpg);
  background-size: 100% 500px;
  height: 450px;
}
.demo-carousel4 {
  background: url(../assets/home/12.jpg);
  background-size: 100% 520px;
  height: 450px;
}
// 用户详情
.users {
  width: 140px;
  height: 110px;
  margin: 20px;
  background: #ffffff;
  overflow: hidden;
  border-radius: 8px;
  position: absolute;
  top: 40px;
  right: 190px;
  animation: showUser 1s;
  -webkit-animation: showUser 1s;
  z-index: 999;
}
.users p {
  cursor: pointer;
  text-align: center;
  width: 90px;
  margin: 0 auto;
  color: #a6a6a6;
}
.users p:hover {
  color: #c0c4cc;
}
.users p i {
  margin-right: 2px;
}
.usersz {
  margin-top: 10px;
}
.downLogin {
  margin-top: 10px;
}
// css动画
@keyframes showUser {
  //  0% {top:0px;right:200px;}
  // 100% { top:12px;right:200px;}
  0% {
    width: 140px;
    height: 0px;
  }
  100% {
    width: 140px;
    height: 110px;
  }
}
@-webkit-keyframes showUser {
  // 0%   {width: 140px;height: 0px;}
  // 100% { width: 140px;height: 110px;}
}
.icon {
  border: 1px solid #ff0000;
  margin-left: 50px;
}
</style>